package chapter03

/**
 * @program lu-scala01
 * @description: 继承
 * @author: zhanglu
 * @create: 2022-03-10 17:35:00
 */
object C07_Inherit {

  def main(args: Array[String]): Unit = {
    val student07_1 = new Student07("lu", 18)
    val student07_2 = new Student07("lu", 18, "001")
    student07_2.printInfo

    val teacher01 = new Teacher
    teacher01.printInfo

    def personInfo(person: Person07): Unit ={
      person.printInfo
    }

    personInfo(teacher01)
    personInfo(student07_2)

  }

}

class Person07 {

  var name: String = _
  var age: Int = _

  println("1.父类的主构造器调用")

  def this(name: String, age: Int){
    this()
    println("2.父类的辅构造器调用")
    this.name = name
    this.age = age
  }

  def printInfo {
    println(s"Person07 $name $age")
  }

}

class Student07(name: String, age: Int) extends Person07(name: String, age: Int){

  var no: String = _

  println("3.子类的主构造器调用")

  def this(name: String, age: Int, no: String){
    this(name, age)
    println("4.子类的辅构造器调用")
    this.no = no
  }

  override def printInfo {
    println(s"Student07 $name $age $no")
  }

}

class Teacher extends Person07{

  override def printInfo: Unit = {
    println(s"Teacher $name $age")
  }

}
